//
//  SelfViewController.m
//  1gene
//
//  Created by 1jiyin on 16/3/17.
//  Copyright © 2016年 1jiyin. All rights reserved.
//
//*******************点击社区首页我的头像的界面*******************
#import "SelfViewController.h"
#import "MyCareViewController.h"
#import "CommunityGoodFriendViewController.h"

@interface SelfViewController ()<SelfTableViewDelegate>
/**
 *定时器
 */
@property(nonatomic,copy)NSTimer *myTimer;
@property(nonatomic,assign)NSInteger myTime;
@property(nonatomic,copy)UIView *deleteView;
@end

@implementation SelfViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:[UIView new]];
    self.view.backgroundColor=[UIColor whiteColor];
    [self createUI];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(cellComing:) name:@"deleteCellTopic" object:nil];
    // Do any additional setup after loading the view.
}

-(void)cellComing:(NSNotification *)notify
{
    _deleteView.hidden=NO;
}
-(void)createUI
{
    self.navigationController.navigationBar.hidden=YES;
    
    SelfTableView *table=[[SelfTableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped UserId:_userId];
    table.imgDelegate=self;
    [self.view addSubview:table];
    
    
    _deleteView=[[UIView alloc]initWithFrame:self.view.bounds];
    [self.view addSubview:_deleteView];
    
    UIButton *backgroundBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    backgroundBtn.backgroundColor=[UIColor blackColor];
    backgroundBtn.alpha=0.3;
    backgroundBtn.frame=_deleteView.bounds;
    [backgroundBtn addTarget:self action:@selector(backgroundCancel:) forControlEvents:UIControlEventTouchUpInside];
    [_deleteView addSubview:backgroundBtn];
    
    UIView *v1=[[UIView alloc]initWithFrame:CGRectMake((self.view.frame.size.width-200)/2.0, 300, 200, 80.5)];
    v1.backgroundColor=[UIColor whiteColor];
    v1.layer.borderColor=[UIColor whiteColor].CGColor;
    v1.layer.borderWidth=1.0;
    v1.layer.cornerRadius=5.0;
    [_deleteView addSubview:v1];
    
    UIButton *deleteBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    deleteBtn.frame=CGRectMake(0, 0, v1.frame.size.width, 80/2.0);
    [deleteBtn setTitle:@"删除帖子" forState:UIControlStateNormal];
    deleteBtn.titleLabel.font=[UIFont systemFontOfSize:16];
    [deleteBtn setTitleColor:[UIColor colorWithRed:84/255.0 green:199/255.0 blue:222/255.0 alpha:1] forState:UIControlStateNormal];
    [deleteBtn addTarget:self action:@selector(deleteBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [v1 addSubview:deleteBtn];
    
    UIView *line=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(deleteBtn.frame), v1.frame.size.width, 0.5)];
    line.backgroundColor=[UIColor colorWithRed:235/255.0 green:235/255.0 blue:241/255.0 alpha:1];
    [v1 addSubview:line];
    
    
    UIButton *cancelDeleteBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    cancelDeleteBtn.frame=CGRectMake(0, 70/2.0+0.5, v1.frame.size.width, 80/2.0);
    [cancelDeleteBtn setTitle:@"取消删除" forState:UIControlStateNormal];
    cancelDeleteBtn.titleLabel.font=[UIFont systemFontOfSize:16];
    [cancelDeleteBtn setTitleColor:[UIColor colorWithRed:84/255.0 green:199/255.0 blue:222/255.0 alpha:1] forState:UIControlStateNormal];
    [cancelDeleteBtn addTarget:self action:@selector(cancelDeleteBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [v1 addSubview:cancelDeleteBtn];
    
    _deleteView.hidden=YES;

}
//删除帖子
-(void)deleteBtnClick:(UIButton *)sender
{
    [[NSNotificationCenter defaultCenter]postNotificationName:@"startDeleteCell" object:nil];
    _deleteView.hidden=YES;
}

//取消删除
-(void)cancelDeleteBtnClick:(UIButton *)sender
{
    _deleteView.hidden=YES;
}


-(void)backgroundCancel:(UIButton *)sender
{
    _deleteView.hidden=YES;
}


//TieBaTableView的代理
-(void)bigImage:(NSInteger)currentIndex AndImageArrays:(NSArray *)imageArrays
{
    CommunityBigImageViewController *vc=[[CommunityBigImageViewController alloc]init];
    // vc.image=img;
    vc.navigationBarState=1;
    vc.imageArrays=[NSArray arrayWithArray:imageArrays];
    vc.currentIndex=currentIndex;
    [self.navigationController pushViewController:vc animated:YES];
}
-(void)gotoXiangQingViewController:(NSInteger)index
{
    TieBaXiangQingViewController *vc=[[TieBaXiangQingViewController alloc]init];
    //vc.arr=arr;
    vc.backState=1;
    vc.topic_id=index;
    vc.centerTag=1;
    self.navigationController.navigationBar.hidden=NO;
    [self.navigationController pushViewController:vc animated:YES];
}
-(void)chooseFunction:(NSInteger)index
{
    //1我关注的
    if (index==1) {
        MyCareViewController *vc=[[MyCareViewController alloc]init];
        vc.userId=[NSString stringWithFormat:@"%ld",_userId];
        vc.myTitle=@"我关注的";
        [self.navigationController pushViewController:vc animated:YES];
    }
    //2我的好友
    else if(index==2){
        CommunityGoodFriendViewController *vc=[[CommunityGoodFriendViewController alloc]init];
        vc.myTitle=@"我的好友";
        [self.navigationController pushViewController:vc animated:YES];
        NSLog(@"进入我的好友界面");
    }
    //我的粉丝
    else if(index==3){
        NSLog(@"用户的id========%ld",_userId);
        FanpageViewController *vc=[[FanpageViewController alloc]init];
        vc.userId=[NSString stringWithFormat:@"%ld",_userId];
        self.navigationController.navigationBar.hidden=NO;
        [self.navigationController pushViewController:vc animated:YES];
    }
    //我的收藏
    else if(index==4){
        MyCollectionViewController *vc=[[MyCollectionViewController alloc]init];
        vc.userId=[NSString stringWithFormat:@"%ld",_userId];
        vc.barState=1;
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}
//返回上一页
-(void)gotoUpViewController
{
    if (_barState==1) {
        //self.navigationController.navigationBar.hidden=NO;
        self.tabBarController.tabBar.hidden=NO;
        [self.navigationController popViewControllerAnimated:YES];
    }else{
        self.navigationController.navigationBar.hidden=NO;
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}
//更多标签按钮点击事件
-(void)moreBiaoQianBtnClick:(NSMutableArray *)arr
{
    BiaoQianViewController *vc=[[BiaoQianViewController alloc]init];
    vc.myTabBarState=1;
    self.navigationController.navigationBar.hidden=NO;
    vc.allBiaoQianArray=[NSMutableArray arrayWithArray:arr];
    [self.navigationController pushViewController:vc animated:YES];
}



//个性签名完整显示
-(void)allPersonalNameBtnClick:name
{
    PersonalNameViewController *vc=[[PersonalNameViewController alloc]init];
    vc.personalName=name;
    vc.myTabBarState=1;
    self.navigationController.navigationBar.hidden=NO;
    self.tabBarController.tabBar.hidden=YES;
    [self.navigationController pushViewController:vc animated:YES];
}

////进入我关注的界面
//-(void)gotoMyAttentionViewController
//{
//    //我关注的
//    MyAttentionViewController *vc=[[MyAttentionViewController alloc]init];
//    vc.barState=1;
//    [self.navigationController pushViewController:vc animated:YES];
//}

//获取数据是否成功
-(void)getDataSuccess:(BOOL)success
{
    if (!success) {
        [self.view showPromptMessage:true and:@"网络状态不佳"];
        if (_myTimer==nil) {
            _myTimer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerRun) userInfo:nil repeats:YES];
        }
    }
}
//启动定时器
-(void)timerRun
{
    if (_myTime>=1) {
        [_myTimer invalidate];
        _myTimer=nil;
        _myTime=0;
        [self.view showPromptMessage:false and:nil];
    }
    _myTime++;
}
-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden=YES;
    if (_myTime!=0) {
        [_myTimer  invalidate];
        _myTimer=nil;
        _myTime=0;
        [self.view showPromptMessage:false and:nil];
    }
}

//发帖
-(void)sendtopicBtnClick
{
    SendTopicViewController *vc=[[SendTopicViewController alloc]init];
    vc.navigationBarState=1;
    self.navigationController.navigationBar.hidden=NO;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
